package command.remoteController.invoker;

import command.remoteController.command.base.Command;

import java.util.ArrayList;

public class Invoker {

    private ArrayList<Command> onCommands;
    private ArrayList<Command> offCommands;

    public Invoker(ArrayList<Command> onCommands, ArrayList<Command> offCommands) {
        this.onCommands = onCommands;
        this.offCommands = offCommands;
    }

    public Invoker() {
        onCommands = new ArrayList<Command>();
        offCommands = new ArrayList<Command>();
    }

    public int addApp(Command onCommand, Command offCommand) {
        onCommands.add(onCommand);
        offCommands.add(offCommand);
        return onCommands.size() - 1;
    }

    public void turnOn(int index) {
        onCommands.get(index).execute();
    }

    public void turnOnUndo(int index) {
        onCommands.get(index).undo();
    }

    public void turnOff(int index) {
        offCommands.get(index).execute();
    }

    public void turnOffUndo(int index) {
        offCommands.get(index).undo();
    }

    public void turnOnAll() {
        for (Command command : onCommands) {
            command.execute();
        }
    }

    public void turnOffAll() {
        for (Command command : offCommands) {
            command.execute();
        }
    }


}
